package org.example.lambda;

import org.example.lambda.Greet;
import org.example.lambda.HelloGreeting;

/**
 * Hello world!
 *
 */
public class Greeter
{

    public void greeting(Greet greet){

        greet.greeting();
    }


    public static void main( String[] args )
    {
        // 无参
        HelloGreeting helloGreeting = new HelloGreeting();                  // 1
        Greet xiXiXiGreetFunction = ()->{System.out.println("xixixi");};    // 2
        Greet innerGreet = new Greet() {                                    // 3 虽然lambda和匿名内部类 很像，但是他们完全是两个东西
            @Override
            public void greeting() {
                System.out.println("innerGreeting");
            }
        };


        Greeter greeter = new Greeter();
        greeter.greeting(helloGreeting);
        greeter.greeting(xiXiXiGreetFunction);
        greeter.greeting(innerGreet);

        // 有参
        AddNumberFunction addNumber =(int a,int b)-> {System.out.println(a+b);};

        addNumber.addNumber(1,2);
    }

}

interface AddNumberFunction{
    void addNumber(int a,int b);
}


